home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7293 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  40 lines

  1. Path: teer1.acpub.duke.edu!jyo
  2. From: John Young Oh <jyo@acpub.duke.edu>
  3. Newsgroups: comp.lang.c
  4. Subject: Ability to locate spaces?
  5. Date: Thu, 15 Feb 1996 22:30:23 -0500
  6. Organization: Duke University, Durham, NC, USA
  7. Message-ID: <Pine.SOL.3.91.960215222301.15979A-100000@teer1.acpub.duke.edu>
  8. NNTP-Posting-Host: teer1.acpub.duke.edu
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11.  
  12. I am trying to write a program that reads an input file and locates where
  13. the spaces are located. For example, if a line from the input file read:
  14. 555555.55    5555.55   5555.55
  15.  
  16. I would like the program to be able to recognize that there are spaces
  17. between the numbers and keep track of them. What I did was to use
  18. fgets and read in the line into a string. I then used a for loop
  19. and checked each array element of the character string and used an
  20. if statement to see if an array element was a space.
  21. Here are the lines of code:
  22.  
  23. FILE *input;
  24. char *string, buf[200];
  25. int i, count;
  26. input = fopen ("data", "r");
  27. (etc etc etc)
  28. string = fgets (buf, 199, input);
  29. for (i = 0; i < 40; ++i)
  30. {
  31.     if (buf[i] == ' ')
  32.     {
  33.         ++count;
  34.     }
  35. }
  36.  
  37. What is wrong with this code? It does not seem to work.
  38.  
  39.             -John Oh
  40.